package com.example.controller;

import com.example.entity.Floor;
import com.example.entity.Stayinfo;
import com.example.entity.Student;
import com.example.mapper.FloorMapper;
import com.example.service.FloorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Floor")
public class FloorConstoller {
    @Autowired
    private FloorMapper floorMapper;
    @Autowired
    private FloorService floorService;

    @GetMapping
    public List<Floor> index(@RequestParam String admin_num) {
        return floorMapper.findAllByadmin_num(admin_num);
    }
    @PostMapping
    public Map<String, Object> save1(@RequestBody Floor floor){
        return floorService.saveFloor(floor);
    }

    @DeleteMapping("/delete")
    public Map<String, Object> deleteByStuNum(@RequestParam String floor_num) {
        return floorService.deleteBy(floor_num);
    }
    @GetMapping("/page")
    public Map<String, Object> findDormitoryPage(@RequestParam Integer pageNum,
                                                 @RequestParam Integer pageSize,
                                                 @RequestParam String category) {
        pageNum = (pageNum - 1) * pageSize;
        List<Floor> data = floorMapper.selectDormitoryPage(pageNum, pageSize, category);
        Integer total = floorMapper.selectDormitoryTotal(category);
        Map<String, Object> res = new HashMap<>();
        res.put("data", data);
        res.put("total", total);
        return res;
    }
}
